<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>AOS傲雄在线--驾校Portal</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/login.css"/>
    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript" src="static/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="static/js/json2.js"></script>
    <script type="text/javascript" src="static/js/menuIcon.js"></script>
    <script src="layui/layui.all.js" charset="utf-8"></script>
    <script src="static/js/base.js" charset="utf-8"></script>
    <script src="static/js/ax.js" charset="utf-8"></script>
    <script src="static/js/md5.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="static/js/html5.js"></script>
    <script src="static/js/respond.js"></script>
    <![endif]-->
</head>
<body>
<div class="hearder">
    <div class="logo">
        <img src="./static/images/logo.png"/>
    </div>
    <h2>登录</h2>
</div>
<div class="login_wrap">
    <!--<form method="post">-->
    <div class="login">
        <p><span></span><input type="text" id="username" placeholder="请输入用户名" name="username" value="admin"/></p>
        <p class="password"><span></span><input type="password" id="password" placeholder="请输入密码" name="password" value="123456"/></p>
        <p class="num"><span></span><input type="text" id="captcha" placeholder="请输入验证码" name="captcha" value=""/>
            <i><img id="imgVCode" onclick="refreshCode(this)"
                    alt="如果看不清楚，请单击图片刷新！" title="点击刷新"/></i></p>
        <h6><label for="remenber"><input id="remenber" type="checkbox"/>记住密码</label><a href="#">忘记密码</a></h6>
        <p class="button_1"><input type="button" value="登录"/></p>
        <p class="button_2"><a href="register.html"><input type="button" value="注册"/></a></p>
    </div>
    <!--</form>-->
</div>

<script>
    $(function () {
        $("#imgVCode").attr("src", schoolWebUrl+"/api/captcha/getcaptcha");
    });


    function refreshCode(obj) {
        obj.src = schoolWebUrl+"/api/captcha/getcaptcha?rnd="+Math.random();
    }


    $('.button_1').click(function () {
        if ($("#username").val() == '' || $("#username").val() == null) {
            layer.msg("用户名为空");
            return false;
        }
        if ($("#password").val() == '' || $("#password").val() == null) {
            layer.msg("密码为空");
            return false;
        }
        if ($("#captcha").val() == '' || $("#captcha").val() == null) {
            layer.msg("验证码为空");
            return false;
        }
        ax.post({
            url: schoolWebUrl+"/user/login",
            contentType: "application/x-www-form-urlencoded",
            data: {username: $("#username").val(), password: hex_md5($("#password").val()), code: $("#captcha").val()},
            success: function (res) {
                if (res.code == 0) {
                    clearCookie('captchaCode');
                    $.cookie(currentUserId, res.data.userId);
                    $.cookie(gatewayAuthorization, res.data.data.token.access_token);
                    //todo 保存权限菜单数据

                    $.cookie(currentUserName, res.data.data.username.split("+")[1]);

                    layer.msg('登录成功');
                    setTimeout(function () {
                        window.location.replace("index.html");
                    },400)

                } else {
                    layer.msg(res.message);
                }
            }

        });
    });
</script>
</body>
</html>
